#ifndef EYERWANDARTIST_EWAUIWIDGET_HPP
#define EYERWANDARTIST_EWAUIWIDGET_HPP

#include <list>
#include <limits.h>

#include "EyerMath/EyerMath.hpp"
#include "EWAUI/EWAUIHeader.hpp"

#include "EWAUILayoutParams.hpp"
#include "EWAUILayoutType.hpp"
#include "EWAUIMouseStatus.hpp"

namespace Eyer
{
    class EWAUIWidget : public EyerRectI
    {
    public:
        virtual int Draw(int level = 0);
        virtual int OnDraw();
        virtual Vec2I OnMeasure(int suggestWidth, int suggestHeight, int level = 0);
        virtual int GetMinWidth();
        virtual int GetMinHeight();
        virtual int SetMinWidth(int minWidth);
        virtual int SetMinHeight(int minHeight);

    public:
        EWAUIWidget(EWAUILayoutParams width, EWAUILayoutParams height);
        virtual ~EWAUIWidget();
        int SetWidgetName(const EyerString & widgetName);
        int AddWidget(const EyerSmartPtr<EWAUIWidget> & widget);
        int RemoveAllWidget();
        int PrintInfo(int level = 0);

    public:
        int RemoveAllUIGraph();
        int AddUIGraph(const EyerSmartPtr<EWAUIGraph> & graph);
        int GetUIGraphSize();
        int SetLayoutType(EWAUILayoutType layoutType);
        EyerSmartPtr<EWAUIGraph> GetUIGraph(int index);
        bool IsDraging();
        int SetMinWH(int w, int h);
        int SetBGColor(const EyerColor & _bgColor);

        int SetChildCustomXY(const Vec2I & _customXY);
    public:
        virtual bool MousePressEvent     (const Vec2I & pos);
        virtual bool MouseReleaseEvent   (const Vec2I & pos);
        virtual bool MouseMoveEvent      (const Vec2I & pos);
        virtual bool ScrollEvent         (const double x, const double y);

        virtual bool OnMousePressEvent     (const Vec2I & pos);
        virtual bool OnMouseReleaseEvent   (const Vec2I & pos);
        virtual bool OnMouseMoveEvent      (const Vec2I & pos);
        virtual bool OnScrollEvent         (const double x, const double y);

    public:
        Vec2I customXY;
        Vec2I minWH;
        EyerString widgetName           = "EWAUIWidget";
        EyerColor bgColor               = EyerColor::BLACK;

        std::vector<EyerSmartPtr<EWAUIWidget>> childWidget;
        std::vector<EyerSmartPtr<EWAUIGraph>> graphList;
        EWAUILayoutParams widthMode     = EWAUILayoutParams::MATCH_PARENT;
        EWAUILayoutParams heightMode    = EWAUILayoutParams::MATCH_PARENT;
        EWAUILayoutType layoutType      = EWAUILayoutType::LinearLayoutVertical;

        EWAUIMouseStatus mouseStatus    = EWAUIMouseStatus::STAND_BY;
        bool isDrag                     = false;
        Vec2I pressPos;
        Vec2I offsetXY;

        // Margin
        int marginTop       = 0;
        int marginBottom    = 0;
        int marginLeft      = 0;
        int marginRight     = 0;

        // align parent
        bool alignParentTop         = false;
        bool alignParentBottom      = false;
        bool alignParentLeft        = false;
        bool alignParentRight       = false;

        Vec2I MeasureChildWidget(const std::vector<EyerSmartPtr<EWAUIWidget>> & childWidget, int suggestWidth, int suggestHeight, int level, bool updateXY);


#ifdef EYER_EWAUI_DEBUG
        int debug_suggestWidth = 0;
        int debug_suggestHeight = 0;
#endif
    };
}

#endif //EYERWANDARTIST_EWAUIWIDGET_HPP
